package com.vitabuybuy.tv.ui.mine.talent.live

import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityLiveNoticeDetailBinding
import com.library.common.base.BaseActivity
import com.vitabuybuy.tv.ui.mine.talent.live.adapter.CommodityExplainListAdapter
import com.vitabuybuy.tv.ui.mine.talent.live.viewmodel.LiveManageViewModel
import com.vitabuybuy.tv.ui.tencent.superplay.PlaybackFragment
import kotlinx.android.synthetic.main.activity_live_replay.*
import kotlinx.android.synthetic.main.activity_live_replay.playback_fragment

class LiveReplayActivity : BaseActivity<LiveManageViewModel, ActivityLiveNoticeDetailBinding>() {

    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_live_replay

    private val commodityExplainListAdapter by lazy { CommodityExplainListAdapter() }

    private var liveId: Int? = null

    override fun onGetBundle(bundle: Bundle?) {
        liveId = bundle?.getInt("liveId")
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.live_replay_1))

        recyclerView.apply {
            layoutManager = LinearLayoutManager(mContext)
            adapter = commodityExplainListAdapter
            isNestedScrollingEnabled = false
        }
    }

    override fun observeData() {
        viewModel.getLiveDetail(liveId)
        viewModel.liveDetils.observe(this, Observer {
            (playback_fragment as PlaybackFragment).setUrl(it.image, it.playUrl)
            commodityExplainListAdapter.setNewData(it.productList)
        })
    }


    companion object {
        fun openActivity(mContext: BaseActivity<*, *>, liveId: Int) {
            mContext.startActivity(
                bundleOf(Pair("liveId", liveId)),
                LiveReplayActivity::class.java
            )
        }
    }
}
